import java.util.List;

/**
 * 920. 会议室
 * 给定一系列的会议时间间隔，包括起始和结束时间[[s1,e1]，[s2,e2]，…(si < ei)，确定一个人是否可以参加所有会议。
 * https://www.lintcode.com/problem/meeting-rooms/description?_from=cat
 * <p>
 * 样例
 * 样例1
 * 输入: intervals = [(0,30),(5,10),(15,20)]
 * 输出: false
 * 解释:
 * (0,30), (5,10) 和 (0,30),(15,20) 这两对会议会冲突
 * <p>
 * 样例2
 * 输入: intervals = [(5,8),(9,15)]
 * 输出: true
 * 解释:
 * 这两个时间段不会冲突
 * <p>
 * 注意事项
 * (0,8),(8,10)在8这这一时刻不冲突
 *
 * @author jeymingwu
 * @date 2019/10/8 16:16
 */
public class L0920_Meeting_Rooms {

    /**
     * Definition of Interval:
     * public class Interval {
     * int start, end;
     * Interval(int start, int end) {
     * this.start = start;
     * this.end = end;
     * }
     * }
     */

    class Interval {
        int start, end;
        Interval(int start, int end) {
            this.start = start;
            this.end = end;
        }
    }

    /**
     * @param intervals: an array of meeting time intervals
     * @return: if a person could attend all meetings
     */
    public boolean canAttendMeetings(List<Interval> intervals) {
        // Write your code here
        for (int i = 0; i < intervals.size(); ++i) {
            for (int j = i + 1; j < intervals.size(); ++j) {
                if (intervals.get(i).start > intervals.get(j).start) {
                    Interval temp = intervals.get(i);
                    intervals.set(i, intervals.get(j));
                    intervals.set(j, temp);
                }
            }
        }
        for (int i = 0; i < intervals.size() - 1; ++i) {
            if (intervals.get(i).end > intervals.get(i + 1).start) {
                return false;
            }
        }
        return true;
    }
}
